package com.example.demo53.ui.Setting;

import androidx.lifecycle.ViewModelProvider;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;


import com.example.demo53.R;
import com.example.demo53.databinding.FragmentSettingBinding;

import com.example.demo53.ui.Setting.ip.NetPairing;
import com.example.demo53.util.Adapter.SettingAdapter;
import com.example.demo53.util.been.SettingItem;

import java.util.ArrayList;


public class SettingFragment extends Fragment {



    private View view;
    private SettingViewModel settingViewModel;
    private FragmentSettingBinding binding;
    private ArrayList<SettingItem> smList= new ArrayList<>();
    private SettingItem item;

    private int PORT;
    private String WIFI_IP;


    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {

        settingViewModel =
                new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(SettingViewModel.class);

        binding = FragmentSettingBinding.inflate(inflater, container, false);
        View root = binding.getRoot();


        init();
        //--------view = root------------using view
        view = inflater.inflate(R.layout.fragment_setting, container, false);
        ListView list = (ListView) view.findViewById(R.id.itemList);
        list.setAdapter(new SettingAdapter(smList, this.getActivity()));

        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {

                    case 0:
                        Intent intent=new Intent();
                        intent.setClass(getActivity(), NetPairing.class);
                        startActivity(intent);
                        break;
                    case 1:

                        break;


                }
            }
        });
        return view;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        initview();
//        setListener();
   }




    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }

    public void init()
    {
        //创建水果对象
        SettingItem sm1 = new SettingItem("网络配对", R.drawable.setuser);
        SettingItem sm2 = new SettingItem("照明组设置", R.drawable.group2);

        //将水果对象添加到集合中
        smList.add(sm1);
        smList.add(sm2);
    }
//    public  void  setListener(){
//
//        tv_clear.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                sb.setLength(0);
//                tv_msg.setText("");
//            }
//        });
//
//    }
//
//    public void initview(){
//
//        setting_item=find
//    }
}